package com.stupro.cjlu.controller;


import com.stupro.cjlu.common.utils.VOToEntity;
import com.stupro.cjlu.common.vo.ResultVO;
import com.stupro.cjlu.common.vo.StudentItemVO;
import com.stupro.cjlu.common.vo.TeacherVO;
import com.stupro.cjlu.config.themis.annotation.Student;
import com.stupro.cjlu.entity.Course;
import com.stupro.cjlu.entity.Students;
import com.stupro.cjlu.entity.Teacher;
import com.stupro.cjlu.service.AdmainService;
import com.stupro.cjlu.service.CourseService;
import com.stupro.cjlu.service.StudentsService;
import com.stupro.cjlu.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2021-05-10
 */
@RestController()
@RequestMapping("/admin")
public class AdmainController extends BaseController {

    @Autowired
    private AdmainService admainService;

    @Autowired
    private StudentsService studentsService;

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private VOToEntity voToEntity;

//    @GetMapping("/getAllStudentInfo")
//    public ResultVO getAllStudentInfo(Integer page){
////        studentsService.get(page);
//        return result(studentsService.getPage(page,null,null));
//    }

    @ApiOperation("获取学生数量")
    @GetMapping("/getStudentCount")
    public ResultVO getStudentPageCount(String className, String name) {
        return studentsService.getPageCount(className, name);
    }

    @GetMapping("/getTeacherCount")
    public ResultVO getTeacherPageCount(String name) {
        return teacherService.getPageCount(name);
    }

    @GetMapping("/getCourseCount")
    public ResultVO getCourseCount(Integer teaID,String name) {
        return courseService.getPageCount(teaID,name);
    }

    @ApiOperation("根据学生id获取学生信息")
    @GetMapping("/{id}")
    public ResultVO get(@PathVariable Integer id) {
        return studentsService.get(id);
    }

    @GetMapping("/teacher/{id}")
    public ResultVO getTeacherID(@PathVariable String id){
        Integer teaID = Integer.parseInt(id);
        return teacherService.get(teaID);
    }


    @ApiOperation("获取学生信息数据,没有总数")
    @GetMapping("/getStudentInfo")
    public ResultVO getStudentInfoByName(Integer page,String name,String claName){
        return studentsService.getPage(page,claName,name);
    }


    @ApiOperation("获取成绩")
    @GetMapping("/getGrade")
    public ResultVO getGrade(Integer page,String studentName,String claName,String courseName){
        return studentsService.getCourse(page, studentName, claName, courseName);
    }

    @ApiOperation("获取老师数据")
    @GetMapping("/getTeacher")
    public ResultVO getTeacher(Integer page,String name){
        return teacherService.getTeacher(page,name);
    }

    @ApiOperation("获取班级")
    @GetMapping("/getCourse")
    public ResultVO getCourse(Integer page,String teacherName,String className){
        return teacherService.getCourse(page,teacherName,className);
    }

    @ApiOperation("创建学生")
    @PostMapping("/createCourse")
    public ResultVO create(@RequestBody @Validated Course entity) {
        return courseService.create(entity);
    }


    @PostMapping("/createStudent")
    public ResultVO createStudent(@RequestBody @Validated Students entity) {
        return studentsService.create(entity);
    }

    @PostMapping("/createTeacher")
    public ResultVO createTeacher(@RequestBody @Validated Teacher entity){
        return teacherService.create(entity);
    }

    @ApiOperation("删除学生")
    @GetMapping("/delStudentByStudentId")
    public ResultVO delStudent(Integer id){return studentsService.delete(id);}

    @ApiOperation("删除老师")
    @GetMapping("/delTeacherByTeacherId")
    public ResultVO delTeacher(Integer id){
        return teacherService.delById(id);
    }

    @ApiOperation("删除课程")
    @GetMapping("/delCourseByCourseId")
    public ResultVO delCourseByCourseId(Integer id){
        return courseService.delCourseByCourseId(id);
    }

    @ApiOperation("更新老师数据")
    @PostMapping("/updateTeacher")
    public ResultVO updateTeacher(@RequestBody TeacherVO teacherVO){
        Teacher teacher = voToEntity.toTeacher(teacherVO);
        return teacherService.update(teacher);
    }

    @ApiOperation("更新学生数据")
    @PostMapping("/updateStudent")
    public ResultVO updateStudent(@RequestBody StudentItemVO studentVO){
        Students student = voToEntity.toStudent(studentVO);
        return studentsService.update(student);
    }


    @ApiOperation("初始化学生密码")
    @GetMapping("/initStudentPwd")
    public ResultVO initStudentPwd(Integer stuID,String name,String stuClass){
        return studentsService.initPwd(stuID,name,stuClass);
    }
}
